<template>
  <div class="app-container" />
</template>

<script>
import { getSettlement, changeStatusByOrderId, removeOrderById } from '@/api/market/settlement'
import waves from '@/directive/waves' // waves directive
import { } from '@/utils'

export default {
  name: 'ComplexTable',
  components: { },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      listLoading: false,
      tableKey: 0,
      listQuery: {
        start: 1,
        perpage: 10,
        keyword: undefined,
        settlement_identity: 0,
        settlement_time: '',
        payment_time: '',
        sort: '+id'
      },
      list: null,
      settlementAdjustPriceDialogVisible: false,
      total: 0,
      settlementForm: {

      }
    }
  },
  created() {
    let settlementId = this.$route.query && this.$route.query.settlementId
    settlementId = parseInt(settlementId)
    if (!isNaN(settlementId)) {
      this.$router.push({ path: 'settlement' })
    }
    this.listLoading = true
    const formData = {
      'settlementId': settlementId
    }
    getSettlement(formData).then(response => {
      if (response.status === 200) {
        this.settlementForm = response.data
      } else {
        this.$message({
          message: response.msg,
          type: 'error'
        })
      }
    })
  },
  methods: {
    handelCannel() {
      this.$router.push({ path: 'settlement' })
    },
    sortChange(data) {
      const { prop, settlement } = data
      if (prop === 'id') {
        this.sortByID(settlement)
      }
    },
    sortByID(settlement) {
      if (settlement === 'ascending') {
        this.listQuery.sort = '+id'
      } else {
        this.listQuery.sort = '-id'
      }
      this.handleFilter()
    },
    handleFilter() {
      this.resetListQuery()
      this.listQuery.start = 1
      this.getList()
    },
    handleModifyStatus(row, status) {
      const _this = this
      const formData = {
        'settlementId': row.identity,
        'status': status
      }
      changeStatusByOrderId(formData).then(response => {
        if (response.status === 200) {
          this.$message({
            message: '操作Success',
            type: 'success'
          })
          // _this.listQuery.start = 1
          _this.getList()
        } else {
          this.$message({
            message: response.msg,
            type: 'error'
          })
        }
      })
    },
    handleDelete(row, index) {
      const _this = this
      const formData = {
        'settlementId': row.identity
      }
      removeOrderById(formData).then(response => {
        if (response.status === 200) {
          this.$message({
            message: '操作Success',
            type: 'success'
          })
          // _this.listQuery.start = 1
          _this.getList()
        } else {
          this.$message({
            message: response.msg,
            type: 'error'
          })
        }
      })
    }
  }
}
</script>
